﻿
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Ledict.ConditionExtract.BLL;
using Ledict.ConditionExtract.Common;
using Ledict.ConditionExtract.Model;
using System.Threading;
namespace Ledict.ConditionExtract
{
    public partial class WB_Manage_Synonyms : Form
    {
        public WB_Manage_Synonyms()
        {
            InitializeComponent();

        }
     

        static WB_Manage_Synonyms _default;
        public static WB_Manage_Synonyms Default
        {
            get
            {
                if (_default == null || _default.IsDisposed)
                {
                    _default = new WB_Manage_Synonyms();
                }
                return _default;
            }
        }

        string EditWBS_ID = "";
        string EditWBS_SynonymWords = "";
        string WhereText = "";

        WordBankBLL wordbankbll = new WordBankBLL();
        WordBankKeyWordsBLL wordbankkeywordsbll = new WordBankKeyWordsBLL();
        WordBankSynonymBLL wordbanksynonymbll = new WordBankSynonymBLL();

        private void WordBookManage_Load(object sender, EventArgs e)
        {
            ShowSynonym();
        }
        #region 同义词库

        /// <summary>
        /// 显示
        /// </summary>
        public void ShowSynonym()
        {
            GV_Synonym.AutoGenerateColumns = false;
            GV_Synonym.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataPager1.ChangePageNumber(1);

        }
        private void dataPager1_PageNumberChanging(object sender, Controls.DataPagerPageIndexChangingEventArgs e)
        {

            var startRowIndex = e.StartRowIndex;
            var maximumRows = e.MaximumRows;
            var endRowIndex = e.StartRowIndex + e.MaximumRows;
         DataTable dt = wordbanksynonymbll.GetList(WhereText);
      
            if (dt.Rows.Count > 0)
            {
                e.TotalCount = dt.Rows.Count;

                DataTable newdt = new DataTable();
                newdt = dt.Clone();
                DataRow[] dr = dt.Select("showindex>" + startRowIndex + " and showindex<=" + endRowIndex);
                for (int i = 0; i < dr.Length; i++)
                {
                    newdt.ImportRow((DataRow)dr[i]);
                }

                GV_Synonym.DataSource = newdt;
            }
            else
            {
                GV_Synonym.DataSource = new DataTable();
            }
        }


        #endregion 

        private void ADD_Synonym_Click(object sender, EventArgs e)
        {
            WB_AddSynonyms wb_addsynonyms = new WB_AddSynonyms();
            wb_addsynonyms.Show();
        }

        private void Update_Synonym_Click(object sender, EventArgs e)
        {
            WB_AddSynonyms wb_addsynonyms = new WB_AddSynonyms();
            for (int i = 0; i <= GV_Synonym.Rows.Count - 1; i++)
            {
                DataGridViewCheckBoxCell check = (DataGridViewCheckBoxCell)GV_Synonym.Rows[i].Cells["Column1"];
                if (Convert.ToBoolean(check.Value) == true)
                {
                    wb_addsynonyms.WBS_ID = GV_Synonym.Rows[i].Cells["WBS_ID"].Value.ToString();
                    wb_addsynonyms.WBS_SynonymWords = GV_Synonym.Rows[i].Cells["WBS_SynonymWords"].Value.ToString();
                    break;
                }
            }
            wb_addsynonyms.Show();
        }
       
        private void GV_Synonym_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            EditWBS_ID = GV_Synonym.Rows[e.RowIndex].Cells["WBS_ID"].Value.ToString();
            EditWBS_SynonymWords = GV_Synonym.Rows[e.RowIndex].Cells["WBS_SynonymWords"].Value.ToString();
            
        }

        private void Delete_Synonym_Click(object sender, EventArgs e)
        {
            string DeleteID = "";
            if (MessageBox.Show("确认要删除数据吗？", "此删除不可恢复", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                try
                {
                    for (int i = 0; i <= GV_Synonym.Rows.Count - 1; i++)
                    {
                        DataGridViewCheckBoxCell check = (DataGridViewCheckBoxCell)GV_Synonym.Rows[i].Cells["Column1"];
                        if (Convert.ToBoolean(check.Value) == true)
                        {
                            DeleteID = GV_Synonym.Rows[i].Cells["WBS_ID"].Value.ToString();
                            if (DeleteID != "")
                            {
                                wordbanksynonymbll.Delete(DeleteID);
                            }

                        }
                    }
                    MessageBox.Show("删除成功!");
                }
                catch (Exception error)
                {
                    MessageBox.Show("删除失败!");
                }
                ShowSynonym();
            }
        }

        private void SelectButton_Click(object sender, EventArgs e)
        {
         
            WhereText = SelectText.Text.Trim();
            dataPager1.ChangePageNumber(1);
        }

       
     







    }
}

    

